<template>
	<view class="">
		<u-form :model="form" ref="uForm" :errorType="errorType">
			<view v-show="!stepStatus">
				<view class="formBox">
					<view class="title">基础信息</view>
					<u-form-item label-width="150rpx" label="活动标题" prop="seckillName"  required><u-input input-align="right"  placeholder="请输入活动标题" v-model="form.seckillName" /></u-form-item>
					<u-form-item label-width="200rpx" label="活动开始时间" prop="timeStart" required>
						<u-input input-align="right"  v-model="form.timeStart" placeholder="请选择时间" disabled @click="openTimeShow('timeStart')" />
					</u-form-item>
					<u-form-item label-width="200rpx" label="活动结束时间" prop="timeEnd" required>
						<u-input input-align="right"  v-model="form.timeEnd" placeholder="请选择时间" disabled @click="openTimeShow('timeEnd')" />
					</u-form-item>
					<u-form-item label-width="200rpx" label="虚拟参加人数" prop="inventedSalesNumber">
            <u-input v-model="form.inventedSalesNumber" input-align="right" placeholder="请输入纯数字" type='number'/>
          </u-form-item>
          <u-form-item :label-position="labelPosition" label-width="150" label="活动门店" prop="joinStores" required>
            <u-radio-group v-model="useStoresName" :width="radioCheckWidth" :wrap="radioCheckWrap">
              <u-radio shape="circle" v-for="(item, index) in useStoresList" @change="radioChange1(item.name, 'useStores', item.value)" :key="index" :name="item.name">
                {{ item.name }}
              </u-radio>
            </u-radio-group>
          </u-form-item>
					<u-form-item label-width="150rpx" label="选择门店" prop="joinStores" v-if="useStoresName=='选择门店'" required>
						<view style="width: 100%;" @click="goselectStore" v-if="form.joinStores.split(',').length && form.joinStores.length != 0 && selectStore.length == 0">
							已选择{{ form.joinStores.split(',').length }}家门店
						</view>
						<view style="width: 100%;" @click="goselectStore" v-else-if="selectStore.length != 0">已选择{{ selectStore.length }}家门店</view>
						<view style="width: 100%;" @click="goselectStore" v-else>请选择门店</view>
					</u-form-item>
				</view>
				<view class="formBox">
					<view class="title">活动信息</view>
					<u-form-item label-position="top" label-width="200rpx" label="活动封面" prop="coverImage" required>
						<view class="remark">支持格式jpg/png，宽高比为4:3，仅限一张图片</view>
						<u-upload
                :max-size="5 * 1024 * 1024"
							width="160"
							:auto-upload="true"
							:action="action"
							name="files"
							:file-list="fileList"
							@on-success="onSuccess"
							@on-list-change="onListChange"
							max-count="1"
							:show-progress="false"
							height="160"
						></u-upload>
					</u-form-item>
					<u-form-item label-position="top" label-width="200rpx" label="详情封面" prop="detailsImage" required>
						<view class="remark">支持格式jpg/png，宽高比为5:2，仅限一张图片</view>
						<u-upload
                :max-size="5 * 1024 * 1024"
							width="160"
							:auto-upload="true"
							:action="action"
							name="files"
							:file-list="fileList1"
							@on-success="onSuccess1"
							@on-list-change="onListChange1"
							max-count="1"
							:show-progress="false"
							height="160"
						></u-upload>
					</u-form-item>
					<u-form-item label-position="top" label-width="150rpx" label="分享封面" prop="shareImage" required>
						<view class="remark">支持格式jpg/png，宽高比为5:4，仅限一张图片</view>
						<u-upload
                :max-size="5 * 1024 * 1024"
                width="160"
                :auto-upload="true"
                :action="action"
                name="files"
                :file-list="fileList2"
                @on-success="onSuccess2"
                @on-list-change="onListChange2"
                max-count="1"
                :show-progress="false"
                height="160"
            ></u-upload>
          </u-form-item>
          <u-form-item label="商品详情" label-width="150" prop="content" required>
            <view style="width: 100%;" @click="goShopDetail">{{ form.content.length > 0 ? '修改活动内容' : '请输入商品详情' }}</view>
            <!-- <u-input input-align="right"  placeholder="请输入商品详情" disabled v-model="model.details" @click="goShopDetail" type="text"></u-input> -->
          </u-form-item>
        </view>
				<view class="formBox">
					<view class="title">商品/服务项目</view>
					<view class="f-c-sb" style="line-height: 100rpx;">
						<view class="value">
							<span style="    color: #fa3534;">*</span>
							商品/服务项目
						</view>
						<view class="f-c-fs" style="color: #2979ff;" @click="addShop(1, 0)">
							<u-icon name="plus-circle-fill" color="#2979ff" style="margin-right: 8rpx;" size="35"></u-icon>
							新增
						</view>
					</view>
					<view class="list" v-for="(item, index) in seckillGsDtos" :key="index">
						<view class="f-c-sb name-wrapper">
							<view class="name">{{ item.goodsServerName }}</view>
							<view class="f-c-fs">
								<u-icon name="edit-pen-fill" style="margin-right: 15rpx;" color="#999999" size="40" @click="addShop(2, index)"></u-icon>
								<u-icon name="trash-fill" color="#999999" size="40" @click="deletShop(index)"></u-icon>
							</view>
						</view>
						<view class="info">
							<view class="f-c-fs num">
								<view class="label">
									原价：
									<text class="value">￥{{ item.goodsServerPrice }}</text>
								</view>
								<view class="label">
									数量：
									<text class="value">{{ item.goodsServerNumber }}</text>
								</view>
							</view>
							<view>
								<view class="">描述（20字符）</view>
								<view>{{ item.goodsServerDescribe }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-show="stepStatus">
				<view class="formBox">
					<view class="title">活动规则</view>
					<u-form-item label-width="150rpx" label="活动原价" prop="costPrice" required><u-input input-align="right"   type='digit' placeholder="请输入活动原价" v-model="form.costPrice" /></u-form-item>
					<u-form-item label-width="200rpx" label="活动现价" prop="nowPrice" required><u-input input-align="right"   type='digit' placeholder="请输入活动现价" v-model="form.nowPrice" /></u-form-item>
					<u-form-item label-width="200rpx" label="可抢购数量" prop="rushBuyNumber"><u-input input-align="right"   type='digit' placeholder="不填写或者0表示无限库存" v-model="form.rushBuyNumber" /></u-form-item>
				</view>
				<view class="formBox">
					<view class="title">用户返佣规则</view>
					<u-form-item label-width="150rpx" label="是否设置" prop="isRakeback" required>
						<u-radio-group v-model="isRakeback">
							<u-radio
								size="50"
								@change="e => radioChange(item.value, 'isRakeback')"
								v-for="(item, index) in isList"
								:key="index"
								:name="item.value"
								:disabled="item.disabled"
							>
								{{ item.name }}
							</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label-width="200rpx" label="一级返佣类型" v-if="isRakeback == 1" prop="oneRakebackType" :required="isRakeback == 1">
						<u-input input-align="right"  v-model="form.oneRakebackTypeStr" placeholder="请选择返佣类型" type="select" :disabled="isRakeback == 2" @click="openSelect('oneRakebackType')" />
					</u-form-item>
					<u-form-item
						label-width="250rpx"
						v-if="isRakeback == 1"
						:label="form.oneRakebackType == 1 ? '一级返佣金额(元)' : form.oneRakebackType == 2 ? '返佣百分比(%)' : '一级返佣金额(元)'"
						prop="oneRakebackValue"
						:required="isRakeback == 1"
					>
						<u-input input-align="right"  :disabled="isRakeback == 2"  type='digit' placeholder="请输入" v-model="form.oneRakebackValue" />
					</u-form-item>
					<u-form-item label-width="200rpx" v-if="isRakeback == 1" label="二级返佣类型" prop="secRakebackType" :required="isRakeback == 1">
						<u-input input-align="right"  v-model="form.secRakebackTypeStr" placeholder="请选择返佣类型" type="select" :disabled="isRakeback == 2" @click="openSelect('secRakebackType')" />
					</u-form-item>
					<u-form-item
						label-width="250rpx"
						v-if="isRakeback == 1"
						:label="form.secRakebackType == 1 ? '二级返佣金额(元)' : form.secRakebackType == 2 ? '返佣百分比(%)' : '二级返佣金额(元)'"
						prop="secRakebackValue"
						:required="isRakeback == 1"
					>
						<u-input input-align="right"  :disabled="isRakeback == 2"  type='digit' placeholder="请输入" v-model="form.secRakebackValue" />
					</u-form-item>
				</view>
				<view class="formBox">
					<view class="title">员工提成设置</view>
					<u-form-item label-width="150rpx" label="是否设置" prop="isCommission" required>
						<u-radio-group v-model="isCommission">
							<u-radio
								size="50"
								@change="e => radioChange(item.value, 'isCommission')"
								v-for="(item, index) in isList"
								:key="index"
								:name="item.value"
								:disabled="item.disabled"
							>
								{{ item.name }}
							</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label-width="200rpx" label="设置提成类型" prop="commissionType" v-if="isCommission == 1" :required="isCommission == 1">
						<u-input input-align="right"  v-model="form.commissionTypeStr" placeholder="请选择提成类型" :disabled="isCommission == 2" type="select" @click="openSelect('commissionType')" />
					</u-form-item>
					<u-form-item
						label-width="250rpx"
						v-if="isCommission == 1"
						:label="form.commissionType == 1 ? '提成金额(元)' : form.commissionType == 2 ? '提成百分比(%)' : '提成金额(元)'"
						prop="commissionValue"
						:required="isCommission == 1"
					>
						<u-input input-align="right" v-if="form.commissionType==1"  :disabled="isCommission == 2"  type='digit' placeholder="请输入" v-model="form.commissionValue" />
						<u-input input-align="right" v-else="form.commissionType==2" :disabled="isCommission == 2"  type='digit' placeholder="请输入" v-model="form.commissionValue" />
					</u-form-item>
					<u-form-item label-width="200rpx" v-if="isCommission == 1" label="添加员工" prop="commissionStaffs" :required="isCommission == 1">
						<view
							style="width: 100%;"
							@click="goselectStaff"
							v-if="form.commissionStaffs.split(',').length && form.commissionStaffs.length != 0 && selectStaff.length == 0"
						>
							已选择{{ form.commissionStaffs.split(',').length }}位员工
						</view>
						<view style="width: 100%;" @click="goselectStaff" v-else-if="selectStaff.length != 0">已选择{{ selectStaff.length }}位员工</view>
						<view style="width: 100%;" @click="goselectStaff" v-else>请选择员工</view>
					</u-form-item>
				</view>
			</view>
		</u-form>
		<view class="f-c-fe" v-if="stepStatus"><view class="privew" @click="submit(2)">预览效果</view></view>
		<view class="lxdBtn" @click="stepStatus = true" v-if="!stepStatus">下一步</view>
		<view class="f-c-sa">
			<view class="lastStep" @click="stepStatus = false" v-if="stepStatus">上一步</view>
			<view class="lxdBtn" @click="submit(1)" v-if="stepStatus">保存</view>
		</view>
		<u-popup mode="bottom" border-radius="22" safe-area-inset-bottom closeable v-model="show">
			<view class="formBox-wrapper">
				<view class="formBox">
          <u-form :model="shop" ref="uShop">
            <u-form-item label-width="200rpx" label="商品服务名称" prop="goodsServerName" required>
              <u-input input-align="right" v-model="shop.goodsServerName"/>
            </u-form-item>
            <u-form-item label="销售价" label-width="200rpx" prop="goodsServerPrice" required>
              <u-input v-model="shop.goodsServerPrice" input-align="right" type="digit"/>
            </u-form-item>
            <u-form-item label="数量" label-width="200rpx" prop="goodsServerNumber" required>
              <u-input v-model="shop.goodsServerNumber" input-align="right" type="digit"/>
            </u-form-item>
            <u-form-item label-width="200rpx" label-position="top" label="备注" prop="goodsServerDescribe">
              <u-input input-align="right" v-model="shop.goodsServerDescribe" maxlength="20" type="textarea "/>
            </u-form-item>
          </u-form>
				</view>

				<view class="lxdBtn" @click="save">保存</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
		<u-picker mode="time" placeholder="请选择时间" @confirm="selectTime" v-model="timeShow" :params="params"></u-picker>
		<u-action-sheet :list="typeList" v-model="typeListShow" @click="actionSheetCallback"></u-action-sheet>
	</view>
</template>

<script>
import {mapGetters} from 'vuex';
import {dateFormat} from '@/utils/common/dateTime';
import {seckillEditEcho, seckillSave} from '@/api/marketing';

export default {
  data() {
    return {
      param: {
        seckillId: ''
      },
      useStoresName: '当前门店',
      useStoresList: [
        {
          name: '当前门店',
          value: 1,
          checked: false
        },
        {
          name: '选择门店',
          value: 2,
          checked: false
        }
      ],
      radioCheckWidth: 'auto',
      radioCheckWrap: false,
			errorType: ['message'],
			fileList1: [],
			fileList2: [],
			fileList: [],
			params: {
	year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false,
				timestamp: true
			},
			show: false,
			timeShow: false,
			typeListShow: false,
			stepStatus: false,
			action: 'https://sj.shopec.com.cn/hty-manage-api/upload/files',
			editStatus: 1, //1、新增 2、编辑
			editStatusIndex: 0, //1、新增 2、编辑
			isCommission: '1',
			isRakeback: 1,
			form: {
				seckillName: '',
				timeStart: '',
				timeEnd: '',
				inventedSalesNumber: '0',
				joinStores: '',
				coverImage: '',
				detailsImage: '',
				shareImage: '',
				content: '',
				costPrice: '',
				nowPrice: '',
				rushBuyNumber: '',
				isRakeback: 1,
				oneRakebackType: '',
				oneRakebackValue: '',
				secRakebackType: '',
				secRakebackValue: '',
				isCommission: 1,
				commissionType: '',
				commissionValue: '',
				commissionStaffs: '',
				createStore: ''
			},
			seckillGsDtos: [],
			isList: [
				{
					name: '是',
					value: 1,
					disabled: false
				},
				{
					name: '否',
					value: 2,
					disabled: false
				}
			],
      typeList: [
        {
          text: '按照固定金额',
          value: 1
        },
        {
          text: '按照固定百分比',
          value: 2
        }
      ],
      rules: {
        seckillName: [
          {
            required: true,
            message: '请输入',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],
        timeStart: [
          {
            required: true,
            message: '请选择时间',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],
        timeEnd: [
          {
            required: true,
            message: '请选择时间',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],
        inventedSalesNumber: [
          {
            message: '请输入数字',
            type: 'number',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],

        content: [
          {
            required: true,
            message: '请输入',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],
        costPrice: [
          {
            // 自定义验证函数，见上说明
            validator: (rule, value, callback) => {
              console.log(value)
              return this.$u.test.amount(value);
            },
            message: '金额格式不正确',
            // 触发器可以同时用blur和change
            trigger: ['change', 'blur']
          }
        ],
        nowPrice: [
          {
            // 自定义验证函数，见上说明
            validator: (rule, value, callback) => {
              console.log(value)

              return this.$u.test.amount(value);
            },
            message: '金额格式不正确',
            // 触发器可以同时用blur和change
            trigger: ['change', 'blur']
          }
        ],
        rushBuyNumber: [
          {
            validator: (rule, value, callback) => {
              console.log(value)

              return this.$u.test.digits(value);
            },
            message: '请输入整数',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ],

        oneRakebackValue: [
          {
            // 自定义验证函数，见上说明
            validator: (rule, value, callback) => {
              if (this.form.isCommission == 1) {
                return this.$u.test.amount(value);
              } else {
                callback();
              }
            },
            message: '金额格式不正确',
            // 触发器可以同时用blur和change
            trigger: ['change', 'blur']
          }
        ],

        secRakebackValue: [
          {
            // 自定义验证函数，见上说明
            validator: (rule, value, callback) => {
              if (this.form.isCommission == 1) {
                return this.$u.test.amount(value);
              } else {
                callback();
              }
            },
            message: '金额格式不正确',
            // 触发器可以同时用blur和change
            trigger: ['change', 'blur']
          }
        ],

        commissionValue: [
          {
            // 自定义验证函数，见上说明
            validator: (rule, value, callback) => {
              if (this.form.isCommission == 1) {
                return this.$u.test.amount(value);
              } else {
                callback();
              }
            },
            message: '金额格式不正确',
            // 触发器可以同时用blur和change
            trigger: ['change', 'blur']
          }
        ]
      },
      selectType: '',
      timeType: '',
      shop: {
        goodsServerName: '',
        goodsServerPrice: '',
        goodsServerNumber: '',
        goodsServerDescribe: ''
      },
      rulesShop: {
        goodsServerName: [
					{
						required: true,
						message: '请输入',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}
				],
				goodsServerPrice: [
					{
						required: true,
						message: '请输入',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}
				],
				goodsServerNumber: [
					{
						required: true,
						message: '请输入',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur']
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(['userInfo', 'selectStore', 'selectStaff'])
  },
  onLoad(option) {
    let objParam = JSON.parse(option.param);
    if (objParam.id) {
      this.param.seckillId = objParam.id;
      this.getData()
    }
  },
  onShow() {
    if (this.$get('addHtml')) {
      this.form.content = this.$get('addHtml');
    }
  },
  onUnload() {
    this.$remove('addHtml');
    this.$remove('seckillDetail');
    this.$store.commit('setSelectStaff', []);

  },
	methods: {
    getData() {
      seckillEditEcho({id: this.param.seckillId}).then(res => {
        console.log(res);
        if (res.code == 1) {
          this.form = res.data;
          if (this.form.oneRakebackType == 2) {
            this.form.oneRakebackValue == this.form.oneRakebackValue * 100;
          }
          if (this.form.secRakebackType == 2) {
            this.form.secRakebackValue == this.form.secRakebackValue * 100;
          }
          if (this.form.commissionType == 2) {
            this.form.commissionValue == this.form.commissionValue * 100;
          }
          if (this.form.joinStores.indexOf(',') != -1) {
            this.useStoresName = '选择门店'
          }
          this.form.oneRakebackTypeStr = this.form.oneRakebackType == 1 ? '按照固定金额' : '按照固定百分比';
          this.form.secRakebackTypeStr = this.form.secRakebackType == 1 ? '按照固定金额' : '按照固定百分比';
          this.form.commissionTypeStr = this.form.commissionType == 1 ? '按照固定金额' : '按照固定百分比';
          this.isCommission = this.form.isCommission;
          this.isRakeback = this.form.isRakeback;
          this.seckillGsDtos = res.data.seckillGsEntities;
          var urlObj = {
            url: '',
            error: false, // 上传失败，此值为true
            progress: 100 // 0-100之间的值
          };
          urlObj.url = this.$imagePath + res.data.coverImage;
          this.fileList.push(urlObj);
          var urlObj1 = {
            url: '',
            error: false, // 上传失败，此值为true
            progress: 100 // 0-100之间的值
          };
          urlObj1.url = this.$imagePath + res.data.detailsImage;
          this.fileList1.push(urlObj1);
          var urlObj2 = {
            url: '',
            error: false, // 上传失败，此值为true
            progress: 100 // 0-100之间的值
          };
          urlObj2.url = this.$imagePath + res.data.shareImage;
          this.fileList2.push(urlObj2);
          delete this.form.id
          this.form.timeEnd = ''
          this.form.timeStart = ''
          this.$forceUpdate()
        }
      });
    },
    onListChange(lists, index) {
      this.fileList = lists;
    },
    onListChange1(lists, index) {
      this.fileList1 = lists;
    },
    onListChange2(lists, index) {
      this.fileList2 = lists;
    },
    addShop(type, index) {
			this.show = true;
			this.editStatus = type;
			this.editStatusIndex = index;
			if (type == 2) {
				this.shop = this.seckillGsDtos[index];
			} else {
				this.shop = {
					goodsServerName: '',
					goodsServerPrice: '',
					goodsServerNumber: '',
					goodsServerDescribe: ''
				};
			}
		},
		deletShop(index) {
			this.seckillGsDtos.splice(index, 1);
		},
		radioChange(e, type) {
			console.log(e);
			this.form[type] = e;
		},
    radioChange1(name, type, value) {
      this[type + 'name'] = name;
      if (name == '选择门店') {
        this.goselectStore()
      } else if (name == '当前门店') {
        this.form.joinStores = this.userInfo.storeBasicId;
      }
    },
		onSuccess(data, index, lists, name) {
			console.log(data, index, lists, name);
			this.form.coverImage = data.data.saveUrl;
		},
		onSuccess1(data, index, lists, name) {
			console.log(data, index, lists, name);
			this.form.detailsImage = data.data.saveUrl;
		},
		onSuccess2(data, index, lists, name) {
			console.log(data, index, lists, name);
			this.form.shareImage = data.data.saveUrl;
		},
		submit(type) {
			if(this.useStoresName=='选择门店') {
        if (this.selectStore.length > 0) {
          var str = '';
          this.selectStore.forEach((val, index) => {
            if (index == this.selectStore.length - 1) {
              str = str + val.storeId;
            } else {
              str = str + val.storeId + ',';
            }
          });
          this.form.joinStores = str;
        }

      }else{
				this.form.joinStores = this.userInfo.storeBasicId
			}

      var str2 = '';
      this.selectStaff.forEach((val, index) => {
        if (index == this.selectStaff.length - 1) {
          str2 = str2 + val.storeUserId;
        } else {
          str2 = str2 + val.storeUserId + ',';
        }
      });
      this.form.commissionStaffs = str2;

      this.$refs.uForm.validate(valid => {
        if (valid) {
          console.log('验证通过');
          var data = {
            ...this.form,
            seckillGsDtos: this.seckillGsDtos
          };
          if (data.seckillGsDtos.length == 0) {
            this.$refs.uToast.show({
              title: '请添加商品',
              type: 'error'
						});
						return;
					}
					if (data.joinStores.length == 0) {
						this.$refs.uToast.show({
							title: '请选择活动门店',
							type: 'error'
						});
						return;
					}
					if (data.coverImage.length == 0) {
						this.$refs.uToast.show({
							title: '请上传活动封面图片',
							type: 'error'
						});
						return;
					}
					if (data.detailsImage.length == 0) {
						this.$refs.uToast.show({
							title: '请上传活动详情图片',
							type: 'error'
						});
						return;
					}
					if (data.shareImage.length == 0) {
						this.$refs.uToast.show({
							title: '请上传分享封面图片',
							type: 'error'
						});
						return;
					}
					if (this.isRakeback == 1) {
						if (data.oneRakebackType.length == 0) {
							this.$refs.uToast.show({
								title: '请选择一级返佣类型',
								type: 'error'
							});
							return;
						}
						if (data.oneRakebackValue.length == 0) {
							this.$refs.uToast.show({
								title: `请输入${data.oneRakebackType == 1 ? '一级返佣金额' : '一级返佣百分比'}`,
								type: 'error'
							});
							return;
						}
						if (data.secRakebackType.length == 0) {
							this.$refs.uToast.show({
								title: '请选择二级返佣类型',
								type: 'error'
							});
							return;
						}
						if (data.secRakebackValue.length == 0) {
							this.$refs.uToast.show({
								title: `请输入${data.secRakebackType == 1 ? '二级返佣金额' : '二级返佣百分比'}`,
								type: 'error'
							});
							return;
						}
					}
					if (this.isCommission == 1) {
						if (data.commissionType.length == 0) {
							this.$refs.uToast.show({
								title: '请选择员工提成类型',
								type: 'error'
							});
							return;
						}
						if (data.commissionValue.length == 0) {
							this.$refs.uToast.show({
								title: `请输入${data.secRakebackType == 1 ? '提成金额' : '提成百分比'}`,
								type: 'error'
							});
							return;
						}
						if (data.commissionStaffs.length == 0) {
							this.$refs.uToast.show({
								title: `请选择员工`,
								type: 'error'
							});
							return;
						}
					}
					if (this.isRakeback == 2) {
						delete data.oneRakebackType;
						delete data.oneRakebackValue;
						delete data.secRakebackType;
						delete data.secRakebackValue;
					}
					if (this.isCommission == 2) {
						delete data.commissionType;
						delete data.commissionValue;
						delete data.commissionStaffs;
					}
					if(data.oneRakebackType==2){
						data.oneRakebackValue==data.oneRakebackValue/100
					}
					if(data.secRakebackType==2){
						data.secRakebackValue==data.secRakebackValue/100
					}
					if(data.commissionType==2){
						data.commissionValue==data.commissionValue/100
					}
					data.createStore = this.userInfo.storeBasicId;
					data.content = encodeURI(data.content);
					this.$put('seckillDetail', data);
					if (type == 2) {
            this.$navigateTo('./preview', {});
            return;
          }
					seckillSave(data).then(res => {
						if (res.code == 1) {
							this.$put('isCreatStatus', '1');
							uni.switchTab({
								url: '/pages/marketing/marketing'
							});
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
					});
				} else {
					console.log('验证失败');
				}
			});
		},

		goselectStore() {
			this.$navigateTo('/pages/selectStore/selectStore', {});
		},
		goselectStaff() {
			this.$navigateTo('/pages/selectStaff/selectStaff', {});
		},
		goShopDetail() {
			this.$put('addHtml', this.form.content);
			this.$navigateTo('/workbench/shopDetail/shopDetail', {});
		},
		openSelect(type) {
			this.selectType = type;
			this.typeListShow = true;
		},
		openTimeShow(type) {
			this.timeType = type;
			this.timeShow = true;
		},
    selectTime(e) {
      console.log(e);
      if (this.timeType == 'timeEnd' && this.form.timeStart.length == 0) {
        this.$refs.uToast.show({
          title: '请选择开始时间',
          type: 'error'
        });
        return;
      } else if (this.timeType == 'timeEnd' && this.form.timeStart.length != 0) {
        var date = new Date(this.form.timeStart);
        if ((e.timestamp+600) * 1000 < date.getTime()) {
          this.$refs.uToast.show({
            title: '结束时间不能小于开始时间',
            type: 'error'
          });
          return;
        }
      }
      if ((e.timestamp+600) * 1000 < +new Date()) {
        this.$refs.uToast.show({
          title: '时间不能小于当前时间',
          type: 'error'
        });
        return;
      }
      this.form[this.timeType] = dateFormat(e.timestamp, 'yyyy-MM-dd');
  },
		// 点击actionSheet回调
		actionSheetCallback(index) {
			console.log(index);
			var key = this.selectType + 'Str';
			this.form[this.selectType] = this.typeList[index].value;
			this.form[key] = this.typeList[index].text;
		},
		save() {
			this.$refs.uShop.validate(valid => {
				if (valid) {
					console.log('验证通过');
					if (this.editStatus == 1) {
						this.seckillGsDtos.push(JSON.parse(JSON.stringify(this.shop)));
					} else if (this.editStatus == 2) {
						this.seckillGsDtos[this.editStatusIndex] = JSON.parse(JSON.stringify(this.shop));
					}
					this.show = false;
				} else {
					console.log('验证失败');
				}
			})
		}
	},
	// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
	onReady() {
		this.$refs.uForm.setRules(this.rules);
		this.$refs.uShop.setRules(this.rulesShop);
	}
};
</script>
<style lang="less" scoped>
.formBox-wrapper {
	height: 70vh;
	padding-top: 50rpx;
}
.list:nth-last-child(1) {
	border: 0;
}
.list {
	border-bottom: 1px solid #ccc;
	width: 100%;
	padding-bottom: 40rpx;

	.name {
		font-size: 28rpx;
		font-weight: 700;
		text-align: left;
		color: #131313;
		line-height: 36px;
	}
	.info {
		line-height: 50rpx;
		.label {
			width: 50%;
			line-height: 80rpx;
		}
	}
}
.lastStep {
	width: 320rpx;
	height: 100rpx;
	opacity: 1;
	border: 2px solid #177fff;
	border-radius: 13rpx;
	font-size: 32rpx;
	text-align: center;
	color: #177fff;
	line-height: 100rpx;
	font-weight: 700;
}
.f-c-sa {
	margin: 50rpx 0;
	.lxdBtn {
		width: 320rpx;
		height: 100rpx;
		margin: 0;
		border-radius: 13rpx;
	}
}
.privew {
	font-size: 32rpx;
	font-weight: bold;
	text-align: left;
	color: #177fff;
	line-height: 64rpx;
	border-bottom: 1px solid #177fff;
	margin: 20rpx 25rpx 70rpx;
}

 .remark {
    font-size: 24rpx;
    color: #888888;
    line-height: 30rpx;
  }
</style>
